import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class TileSimple extends StatelessWidget {
  final String title;
  final TextStyle? titleStyle;
  final Widget? icon;
  final Widget? action;
  final String? actionText;
  final Color? actionTextColor;
  final BorderRadiusGeometry borderRadius;
  final EdgeInsetsGeometry? padding;
  final bool showArrow;
  final void Function()? onPressed;

  const TileSimple({
    super.key,
    required this.title,
    this.titleStyle,
    this.icon,
    this.action,
    this.actionText,
    this.actionTextColor,
    this.borderRadius = BorderRadius.zero,
    this.padding,
    this.showArrow = true,
    this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ElevatedButton.styleFrom(
        padding: padding ?? EdgeInsets.all(16.w),
        backgroundColor: context.theme.colorScheme.primaryContainer,
        disabledBackgroundColor: context.theme.colorScheme.primaryContainer,
        shape: RoundedRectangleBorder(
          borderRadius: borderRadius,
        ),
      ),
      child: Row(
        children: [
          Expanded(
            flex: 1,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: titleStyle ??
                      context.theme.textTheme.headlineMedium?.copyWith(
                        color: context.theme.colorScheme.primary,
                      ),
                  // 允许自动换行，不设置maxLines和overflow
                ),
              ],
            ),
          ),
          actionText != null
              ? Expanded(
                  flex: 1,
                  child: Text(
                    actionText!,
                    style: context.theme.textTheme.bodyMedium?.copyWith(
                      color: actionTextColor ?? context.theme.colorScheme.onPrimary,
                    ),
                    // 允许自动换行，不设置maxLines和overflow
                    textAlign: TextAlign.right,
                  ),
                )
              : (action != null
                  ? action!
                  : const SizedBox.shrink()),
          SizedBox(width: showArrow ? 4.w : 0),
          showArrow
              ? Icon(
                  Icons.chevron_right,
                  size: 14.w,
                  color: context.theme.colorScheme.tertiary,
                )
              : const SizedBox.shrink(),
        ],
      ),
    );
  }
}
